<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
    <title>MSPBots teams sync data service</title>
    <link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css"
          integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" rel="stylesheet">


</head>
<body>
<div class="jumbotron">
    <h1 class="display-4">Welcome MSPBots teams API!</h1>
    <hr class="my-4">
    <p>It uses utility classes for typography and spacing to space content out within the larger container.</p>
    <a class="btn btn-primary btn-lg" href="/documentation/swagger-ui/" role="button">Swagger Api Documentation</a>
    <a class="btn btn-primary btn-lg" href="javascript:void(0)"
       onclick="openUser()" role="button">Allow access your user account</a>
    <a class="btn btn-primary btn-lg" href="javascript:void(0)"
       onclick="openAdmin()" role="button">Allow access your admin account</a>

    <a class="btn btn-primary btn-lg" href="javascript:void(0)"
       onclick="login()" role="button">Login up</a>
</div>

<script integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g=="
        src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js"
        crossorigin="anonymous"></script>

<script integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx"
        src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"
        crossorigin="anonymous"></script>

<script type="text/javascript" src="https://alcdn.msauth.net/lib/1.3.0/js/msal.min.js"></script>

<script type="text/javascript">
    const config = {
        auth: {
            clientId: "7262864b-731f-438c-b58d-db28b11fa879"
        }
    }
    const msalInstance = new Msal.UserAgentApplication(config);

    function authCallback(error, response) {
        //handle redirect response
    }

    // (optional when using redirect methods) register redirect call back for Success or Error
    msalInstance.handleRedirectCallback(authCallback);
    const loginRequest = {
        scopes: ["user.read"] // optional Array<string>
    };

    function login() {
        msalInstance.loginPopup(loginRequest)
            .then(response => {
                console.log("log is succcess.");
                console.log(response);
            })
            .catch(err => {
                console.log("log is error.");
                console.log(err);
            });
    }

    function openUser() {
        window.open('https://login.microsoftonline.com/common/oauth2/v2.0/authorize?' +
            'client_id=7262864b-731f-438c-b58d-db28b11fa879' +
            '&response_type=code' +
            '&redirect_uri=http://localhost:8080/oauth/redirect' +
            '&response_mode=query&prompt=select_account' +
            '&scope=offline_access user.read User.ReadBasic.All' +
            '&state={"tenantId":1,"tokenType":"user"}',
            'MSP Bots are to get your permission', "width=auto,height=600,resizable,scrollbars=no,status=1");
    }

    function openAdmin() {
        window.open('https://login.microsoftonline.com/common/oauth2/v2.0/authorize?' +
            'client_id=7262864b-731f-438c-b58d-db28b11fa879' +
            '&response_type=code' +
            '&redirect_uri=http://localhost:8080/oauth/redirect' +
            '&response_mode=query&prompt=select_account' +
            '&scope=offline_access user.read User.ReadBasic.All User.Read.All Group.Read.All Application.Read.All' +
            '&state={"tenantId":1,"tokenType":"admin"}',
            'MSPBots are to get your permission', "width=auto,height=400,resizable,scrollbars=no,status=1");
    }
</script>
</body>
</html>
